<?php
require_once ('simpletest/autorun.php');

require_once ('../computepercentage.php');

class TestComputingPercentage extends UnitTestCase {

	function testComputePercentage() {
		# signature: computePercentage($start, $target, $current)

		$this -> assertTrue(file_exists('../computepercentage.php'));

		# Test yes/no measure type

		$result1 = computePercentage("no", "yes", "yes");
		$result2 = computePercentage("no", "yes", "no");

		$this -> assertEqual($result1, 100);
		$this -> assertEqual($result2, 0);

		# Test division by 0

		$result3 = computePercentage(10, 10, 10);
		$this -> assertEqual($result3, 100);

		#Test in positive range of numbers and 0

		$result4 = computePercentage(0, 10, 5);
		$result5 = computePercentage(10, 20, 12.5);
		$result6 = computePercentage(10, 20, 10);
		$result7 = computePercentage(10, 20, 20);
		$result8 = computePercentage(0, 0, 0);

		$this -> assertEqual($result4, 50);
		$this -> assertEqual($result5, 25);
		$this -> assertEqual($result6, 0);
		$this -> assertEqual($result7, 100);
		$this -> assertEqual($result8, 100);

		# Test negative number range

		$result9 = computePercentage(0, -10, -5);
		$result10 = computePercentage(-10, -20, -12.5);
		$result11 = computePercentage(-10, -20, -10);
		$result12 = computePercentage(-10, -20, -20);

		$this -> assertEqual($result9, 50);
		$this -> assertEqual($result10, 25);
		$this -> assertEqual($result11, 0);
		$this -> assertEqual($result12, 100);

		# Test mixed number range

		$result13 = computePercentage(-10, 10, 0);
		$result14 = computePercentage(10, -10, 5);
		$result15 = computePercentage(-10, 10, -10);
		$result16 = computePercentage(10, -10, -10);

		$this -> assertEqual($result13, 50);
		$this -> assertEqual($result14, 25);
		$this -> assertEqual($result15, 0);
		$this -> assertEqual($result16, 100);
	}
}
?>